package com.april.pattern.structural.proxy.staticproxy;

import com.april.pattern.structural.proxy.OrderService;
import com.april.pattern.structural.proxy.Order;
import com.april.pattern.structural.proxy.OrderServiceImpl;

/**
 * @author April
 * @version V1.0.0
 * @date 2019/07/06 16:34
 * @description 静态代理
 */
public class OrderServiceStaticProxy {
    private OrderService iOrderService;

    public int saveOrder(Order order) {
        beforeMethod(order);

        iOrderService = new OrderServiceImpl();
        int result = iOrderService.saveOrder(order);

        afterMethod();
        return result;
    }

    private void beforeMethod(Order order) {
        int userId = order.getUserId();
        int dbRouter = userId % 2;
        System.out.println("静态代理分配到【db" + dbRouter + "】处理数据");

        System.out.println("静态代理 before code");
    }

    private void afterMethod() {
        System.out.println("静态代理 after code");
    }
}
